﻿#include "RelationshipDialog.h"
#include "../../MirGraphics/MLibrary.h"
#include "../../MirSounds/SoundManager.h"
#include "../../../Shared/Language.h"
#include "../../Settings.h"

using namespace Client::MirControls;
using namespace Client::MirGraphics;
using namespace Client::MirNetwork;
using namespace Client::MirSounds;
namespace C = ClientPackets;

namespace Client::MirScenes::Dialogs
{

    RelationshipDialog::RelationshipDialog()
    {
        setIndex(583);
        setLibrary(Libraries::Prguse);
        setMovable(true);
        setSort(true);
        setLocation(getCenter());

        TitleLabel = new MirImageControl();
        TitleLabel->setIndex(52);
        TitleLabel->setLibrary(Libraries::Title);
        Point tempVar(18, 8);
        TitleLabel->setLocation(&tempVar);
        TitleLabel->setParent(this);

        CloseButton = new MirButton();
        CloseButton->setHoverIndex(361);
        CloseButton->setIndex(360);
        Point tempVar2(260, 3);
        CloseButton->setLocation(&tempVar2);
        CloseButton->setLibrary(Libraries::Prguse2);
        CloseButton->setParent(this);
        CloseButton->setPressedIndex(362);
        CloseButton->setSound(SoundList::ButtonA);
        CloseButton->Click += [&] (o, e)
        {
            Hide();
        };

        AllowButton = new MirButton();
        AllowButton->setHoverIndex(611);
        AllowButton->setIndex(610);
        Point tempVar3(50, 164);
        AllowButton->setLocation(&tempVar3);
        AllowButton->setLibrary(Libraries::Prguse);
        AllowButton->setParent(this);
        AllowButton->setPressedIndex(612);
        AllowButton->setSound(SoundList::ButtonA);
        AllowButton->setHint(GameLanguage::SwitchMarriage);
        AllowButton->Click += [&] (o, e)
        {
            C::ChangeMarriage tempVar4();
            Network::Enqueue(&tempVar4);
        };

        RequestButton = new MirButton();
        RequestButton->setHoverIndex(601);
        RequestButton->setIndex(600);
        Point tempVar5(85, 164);
        RequestButton->setLocation(&tempVar5);
        RequestButton->setLibrary(Libraries::Prguse);
        RequestButton->setParent(this);
        RequestButton->setPressedIndex(602);
        RequestButton->setSound(SoundList::ButtonA);
        RequestButton->setHint(GameLanguage::RequestMarriage);
        RequestButton->Click += [&] (o, e)
        {
            if (LoverName != "")
            {
                GameScene::Scene->ChatDialog->ReceiveChat("You're already married.", ChatType::System);
                return;
            }
    
            C::MarriageRequest tempVar6();
            Network::Enqueue(&tempVar6);
        };

        DivorceButton = new MirButton();
        DivorceButton->setHoverIndex(617);
        DivorceButton->setIndex(616);
        Point tempVar7(120, 164);
        DivorceButton->setLocation(&tempVar7);
        DivorceButton->setLibrary(Libraries::Prguse);
        DivorceButton->setParent(this);
        DivorceButton->setPressedIndex(618);
        DivorceButton->setSound(SoundList::ButtonA);
        DivorceButton->setHint(GameLanguage::RequestDivorce);
        DivorceButton->Click += [&] (o, e)
        {
            if (LoverName == "")
            {
                GameScene::Scene->ChatDialog->ReceiveChat("You're not married.", ChatType::System);
                return;
            }
    
            C::DivorceRequest tempVar8();
            Network::Enqueue(&tempVar8);
        };

        MailButton = new MirButton();
        MailButton->setHoverIndex(438);
        MailButton->setIndex(437);
        Point tempVar9(155, 164);
        MailButton->setLocation(&tempVar9);
        MailButton->setLibrary(Libraries::Prguse);
        MailButton->setParent(this);
        MailButton->setPressedIndex(439);
        MailButton->setSound(SoundList::ButtonA);
        MailButton->setHint(GameLanguage::MailLover);
        MailButton->Click += [&] (o, e)
        {
            if (LoverName == "")
            {
                GameScene::Scene->ChatDialog->ReceiveChat("You're not married.", ChatType::System);
                return;
            }
    
            GameScene::Scene->MailComposeLetterDialog->ComposeMail(LoverName);
        };

        WhisperButton = new MirButton();
        WhisperButton->setHoverIndex(567);
        WhisperButton->setIndex(566);
        Point tempVar10(190, 164);
        WhisperButton->setLocation(&tempVar10);
        WhisperButton->setLibrary(Libraries::Prguse);
        WhisperButton->setParent(this);
        WhisperButton->setPressedIndex(568);
        WhisperButton->setSound(SoundList::ButtonA);
        WhisperButton->setHint(GameLanguage::WhisperLover);
        WhisperButton->Click += [&] (o, e)
        {
            if (LoverName == "")
            {
                GameScene::Scene->ChatDialog->ReceiveChat("You're not married.", ChatType::System);
                return;
            }
    
            if (MapName == "")
            {
                GameScene::Scene->ChatDialog->ReceiveChat("Lover is not online", ChatType::System);
                return;
            }
            GameScene::Scene->ChatDialog->ChatTextBox->SetFocus();
            GameScene::Scene->ChatDialog->ChatTextBox->setText(":)");
            GameScene::Scene->ChatDialog->ChatTextBox->setVisible(true);
            GameScene::Scene->ChatDialog->ChatTextBox->TextBox->SelectionLength = 0;
            GameScene::Scene->ChatDialog->ChatTextBox->TextBox->SelectionStart = GameScene::Scene->ChatDialog->ChatTextBox->getText().length();
        };

        LoverNameLabel = new MirLabel();
        Point tempVar11(30, 40);
        LoverNameLabel->setLocation(&tempVar11);
        Size tempVar12(200, 30);
        LoverNameLabel->setSize(&tempVar12);
        LoverNameLabel->setBackColour(Color::Empty);
        LoverNameLabel->setForeColour(Color::LightGray);
        LoverNameLabel->setDrawFormat(TextFormatFlags::VerticalCenter);
        LoverNameLabel->setParent(this);
        LoverNameLabel->setNotControl(true);
        Font tempVar13(Settings::FontName, 10.0F);
        LoverNameLabel->setFont(&tempVar13);

        LoverDateLabel = new MirLabel();
        Point tempVar14(30, 65);
        LoverDateLabel->setLocation(&tempVar14);
        Size tempVar15(200, 30);
        LoverDateLabel->setSize(&tempVar15);
        LoverDateLabel->setBackColour(Color::Empty);
        LoverDateLabel->setForeColour(Color::LightGray);
        LoverDateLabel->setDrawFormat(TextFormatFlags::VerticalCenter);
        LoverDateLabel->setParent(this);
        LoverDateLabel->setNotControl(true);
        Font tempVar16(Settings::FontName, 10.0F);
        LoverDateLabel->setFont(&tempVar16);

        LoverLengthLabel = new MirLabel();
        Point tempVar17(30, 90);
        LoverLengthLabel->setLocation(&tempVar17);
        Size tempVar18(200, 30);
        LoverLengthLabel->setSize(&tempVar18);
        LoverLengthLabel->setBackColour(Color::Empty);
        LoverLengthLabel->setForeColour(Color::LightGray);
        LoverLengthLabel->setDrawFormat(TextFormatFlags::VerticalCenter);
        LoverLengthLabel->setParent(this);
        LoverLengthLabel->setNotControl(true);
        Font tempVar19(Settings::FontName, 10.0F);
        LoverLengthLabel->setFont(&tempVar19);

        LoverOnlineLabel = new MirLabel();
        Point tempVar20(30, 115);
        LoverOnlineLabel->setLocation(&tempVar20);
        Size tempVar21(200, 30);
        LoverOnlineLabel->setSize(&tempVar21);
        LoverOnlineLabel->setBackColour(Color::Empty);
        LoverOnlineLabel->setForeColour(Color::LightGray);
        LoverOnlineLabel->setDrawFormat(TextFormatFlags::VerticalCenter);
        LoverOnlineLabel->setParent(this);
        LoverOnlineLabel->setNotControl(true);
        Font tempVar22(Settings::FontName, 10.0F);
        LoverOnlineLabel->setFont(&tempVar22);
    }

    void RelationshipDialog::UpdateInterface()
    {
        LoverNameLabel->setText("Lover:  " + LoverName);

        if (MapName != "")
        {
            LoverOnlineLabel->setText("Location:  " + MapName);
        }
        else
        {
            LoverOnlineLabel->setText("Location:  Offline");
        }

        if ((LoverName == "") && (Date != nullptr))
        {
            if (Date < DateTime(2000))
            {
                LoverDateLabel->setText("Date: ");
                LoverLengthLabel->setText("Length: ");
            }
            else
            {
                LoverDateLabel->setText("Divorced Date:  " + Date.ToShortDateString());
                LoverLengthLabel->setText("Time Since: " + std::to_string(MarriedDays) + " Days");
            }


            LoverOnlineLabel->setText("Location: ");
            AllowButton->setHint(GameLanguage::SwitchMarriage);
        }
        else
        {
            LoverDateLabel->setText("Marriage Date:  " + Date.ToShortDateString());
            LoverLengthLabel->setText("Length: " + std::to_string(MarriedDays) + " Days");
            AllowButton->setHint("Allow/Block Recall");
        }


    }
}
